<?php
  /**
   * This class provides static methods to access and modify the $_GET variable
   * It is recommended to used this instead of accessing the $_GET variable directly
   *
   * @author Macdonald Terrence Robinson
   * @package Core
   *
   */
  final class Get
  {
    public static function init()
    {
      if( !isset($_GET) )
        $_GET = array();
    }
    
    public static function getByKey($keyName)
    {
      return self::getValueWhereKeyContains($keyName);
    }

    public static function isExists($keyName)
    {
      if(self::getValueWhereKeyContains($keyName) !='')
        return true;
      else
        return false;
    }
    
    private static function getValueWhereKeyContains( $keySubString )
    {
      if( isset($_GET[$keySubString]) )
      {
        foreach ($_GET as $key=>$value)
        {
          if( stristr($key, $keySubString) )
          {
            $_GET[$keySubString] = $value;
            break;
          }
        }
      }

      return isset($_GET[$keySubString]) ? $_GET[$keySubString] : NULL;
    }

    public static function set($keyName, $keyValue)
    {
      $_GET[$keyName] =  serialize($keyValue);
    }

    public static function remove($keyName)
    {
      if( self::isExists($keyName) )
        unset($array[$keyName]);
    }

    public static function rename($key, $newKey)
    {
      $tmp = $_GET[$key];
      unset($_GET[$key]);
      self::set($newKey, $tmp);
    }

    public static function setAll(array $newArray)
    {
      $_GET = $newArray;
    }

    public static function clear()
    {
      $_GET = array();
    }
    
    public static function getAll()
    {
      return $_GET;
    }
    
  }
?>
